from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
import yaml


# 从 config.yaml 中加载数据库配置
config_path = './config.yaml'
with open(config_path, 'r') as f:
    config = yaml.safe_load(f)['database']

# 创建 PostgreSQL 连接引擎
DATABASE_URL = \
    f"postgresql://{config['user']}:{config['password']}@{config['host']}:{config['port']}/{config['dbname']}"
engine = create_engine(DATABASE_URL)

# 创建一个基类
Base = declarative_base()

# 创建会话
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
